package com.xyebank.ledger.service.zl.adapter.sjd;

import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LPaymentInf;
import com.xyebank.ledger.service.common.conveter.PayBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.util.StatusConvertUtil;
import com.xyebank.ledger.vo.deal.ZLSJDPaymentVo;

@Component(value = "zlSjdPayBeanConverter")
public class ZLPayBeanConverter implements PayBeanConverter<ZLSJDPaymentVo> {

    ModelMapper modelMapper = new ModelMapper();


    class ZLPayPropertyMap extends PropertyMap<ZLSJDPaymentVo, LPaymentInf> {
        protected void configure() { //注意　不要有重复的映射，不然会报错
            map(source.getOrderNo(), destination.getOrgOrderNo());
            map(source.getMblNo(), destination.getMblNo());
            map(source.getInstallTotalAmt(), destination.getLoanAmount());
            map(source.getInstallTotalCnt(), destination.getLoanPeriod());
            map(source.getLoanDate(), destination.getLoanTime());
        }
    }

    public ZLPayBeanConverter() {
        modelMapper.addMappings(new ZLPayPropertyMap());
    }

    @Override
    public LPaymentInf covert(ZLSJDPaymentVo x) {
        LPaymentInf entity = modelMapper.map(x, LPaymentInf.class);
        entity.setId(IDUtil.generateId(x.getId().toString(), "zl_sjd"));
        entity.setDataSource(CommonConstant.SJD_STR);
        entity.setOrgNo(ProductConstant.ZL_LOAN_ORG);
        buildXyProdNo(entity, x.getProductNo());
        entity.setLoanStatus(StatusConvertUtil.convertPayStatus(x.getOrderStatus()));
        return entity;
    }
    

    
    private void buildXyProdNo(LPaymentInf pEntity, String pProductNo) {
        switch(pProductNo){
            case "P0000073":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000072":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000067":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000066":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000060":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000069":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000088":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "XJBL001":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_BLD_PROD_ID);
                break;
            case "P0000222":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_YZD_PROD_ID);
                break;
            case "XJDQ001":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_DQD_PROD_ID);
                break;
            case "P0048796":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_GJJD_PROD_ID);
                break;
            case "P0000132":
                pEntity.setProductNo(ProductConstant.ZL_LOAN_SJSH_PROD_ID);
                break;
            default:
                pEntity.setProductNo(ProductConstant.ZL_LOAN_SJSH_PROD_ID);
                break;
        }
    }
    
}
